package dao.impl;

import bean.User;
import dao.BaseDao;
import dao.UserDao;

public class UserDaoImpl extends BaseDao<User> implements UserDao {

    @Override
    public User queryUserByUserId(String userId) {
        String sql = "select `userCode` from smbms_user where `userCode` = ?";
        return queryForOne(sql,userId);
    }

    @Override
    public int insertUser(User user) {
//        user.setAuthority();
        String sql = "insert into smbms_user(userCode, userName, userPassword, " +
                "gender, birthday, phone, address, userRole)" + "values(?,?,?,?,?,?,?,?)";
        return update(sql,user.getUserCode(), user.getUserName(),
                user.getUserPassword(), user.getGender(), user.getBirthday(),
                user.getPhone(), user.getAddress(), user.getUserRole());
    }

    @Override
    public User queryUserByUserIdAndPassword(String userCode, String userPassword) {
        String sql = "select * from smbms_user where `userCode` = ? and `userPassword` = ?";
        return queryForOne(sql,userCode,userPassword);
    }
}
